#----------------------
# qstrip -- strip quote 
#
# Argument 1 is the string who has quotes 
# E.G. use like this:
# $(call qstrip,$(STRING_WITH_QUOTE))
#----------------------

define qstrip
$(strip $(subst ",,$(1)))
endef
#"))


WGET 		:= wget --passive-ftp -nd
BZCAT 		:= bzcat
INSTALL 	:= install
TAR_OPTIONS 	:= -xvf
MK_KERNEL_MIRROR := "http://www.kernel.org/pub/"
MK_GNU_MIRROR 	:= "http://ftp.gnu.org/pub/gnu"
TCHAIN_PATCH_DIR := $(srctree)/tchain/patches
INSTALL_BIN	 := $(INSTALL) -m0755
INSTALL_DIR	 := $(INSTALL) -d -m0755
INSTALL_DATA	 := $(INSTALL) -m0644
INSTALL_CONF	 := $(INSTALL) -m0600
GNU_TARGET_SUFFIX := "linux-uclibc"
GNU_BUILD_SUFFIX = "pc-linux-gnu"
OPTIMIZE_FOR_CPU := $(ARCH)
REAL_GNU_TARGET_NAME = $(OPTIMIZE_FOR_CPU)-$(call qstrip,$(GNU_TARGET_SUFFIX))
TCHAIN_SYSROOT_STAGING_DESTDIR=DESTDIR=$(STAGING_DIR)/
TCHAIN_SYSROOT_PREFIX=$(STAGING_DIR)
HOST_ARCH:=$(shell $(HOSTCC) -dumpmachine | sed -e s'/-.*//' \
	-e 's/sparc.*/sparc/' \
	-e 's/arm.*/arm/g' \
	-e 's/m68k.*/m68k/' \
	-e 's/ppc/powerpc/g' \
	-e 's/v850.*/v850/g' \
	-e 's/sh[234]/sh/' \
	-e 's/mips-.*/mips/' \
	-e 's/mipsel-.*/mipsel/' \
	-e 's/cris.*/cris/' \
	-e 's/i[3-9]86/i386/' \
	)
GNU_HOST_NAME	:= $(HOST_ARCH)-$(call qstrip,$(GNU_BUILD_SUFFIX))
TCHAIN_CONFIG_DEVEL_SYSROOT=--with-sysroot=$(TOOL_BUILD_DIR)/uClibc_dev/
TCHAIN_CONFIG_STAGING_SYSROOT=--with-sysroot=$(STAGING_DIR)
DISABLE_NLS	:= --disable-nls
MULTILIB	:= --disable-multilib
SOFT_FLOAT_CONFIG_OPTION	:= --with-float=soft
HOST_LIBEXT	:= .a
HOST_SHREXT	:= .so
ifeq ($(CONFIG_TARGET_LIB_EXT_A),y)
LIBTGTEXT	:= .a
else
LIBTGTEXT	:= .so
endif
QUIET		:= ""

HOST_CONFIGURE_OPTS=PATH=$(HOST_PATH) \
		AR="$(HOSTAR)" \
		AS="$(HOSTAS)" \
		LD="$(HOSTLD) $(HOST_LDFLAGS)" \
		NM="$(HOSTNM)" \
		CC="$(HOSTCC) $(HOST_CFLAGS)" \
		GCC="$(HOSTCC) $(HOST_CFLAGS)" \
		CXX="$(HOSTCXX) $(HOST_CXXFLAGS)" \
		CPP="$(HOSTCPP) $(HOST_CFLAGS)" \
		AR_FOR_BUILD="$(HOSTAR)" \
		AS_FOR_BUILD="$(HOSTAS)" \
		CC_FOR_BUILD="$(HOSTCC)" \
		GCC_FOR_BUILD="$(HOSTCC)" \
		CXX_FOR_BUILD="$(HOSTCXX)" \
		LD_FOR_BUILD="$(HOSTLD)" \
		FC_FOR_BUILD="$(HOSTFC)" \
		CFLAGS_FOR_BUILD="$(HOST_CFLAGS)" \
		CXXFLAGS_FOR_BUILD="$(HOST_CXXFLAGS)" \
		LDFLAGS_FOR_BUILD="$(HOST_LDFLAGS)" \
		FCFLAGS_FOR_BUILD="$(HOST_FCFLAGS)" \
		AR_FOR_TARGET="$(TARGET_AR)" \
		AS_FOR_TARGET="$(TARGET_AS)" \
		CC_FOR_TARGET="$(TARGET_CC)" \
		LD_FOR_TARGET="$(TARGET_LD)" \
		NM_FOR_TARGET="$(TARGET_NM)" \
		RANLIB_FOR_TARGET="$(TARGET_RANLIB)" \
		STRIP_FOR_TARGET="$(TARGET_STRIP)" \
		OBJCOPY_FOR_TARGET="$(TARGET_OBJCOPY)" \
		OBJDUMP_FOR_TARGET="$(TARGET_OBJDUMP)" \
		DEFAULT_ASSEMBLER="$(TARGET_AS)" \
		DEFAULT_LINKER="$(TARGET_LD)" \
		ORIGINAL_AS_FOR_TARGET="$(TARGET_AS)" \
		ORIGINAL_LD_FOR_TARGET="$(TARGET_LD)" \
		ORIGINAL_NM_FOR_TARGET="$(TARGET_NM)" \
		ORIGINAL_OBJDUMP_FOR_TARGET="$(TARGET_OBJDUMP)" \
		PKG_CONFIG="$(PKG_CONFIG_HOST_BINARY)" \
		PKG_CONFIG_PATH="$(HOST_DIR)/usr/lib/pkgconfig$(PKG_CONFIG_PATH)"


#
# config the var in this lib
#
DOWNLOAD_DIR := $(DL_DIR)

################################################################################
# DOWNLOAD -- Download helper. Will try to download source from:
# 1) DOWN_DEF_SITE if enabled
# 2) Download site
#
# Argument 1 is the source location
# Argument 2 is the source filename
#
# E.G. use like this:
# $(call DOWNLOAD,$(FOO_SITE),$(FOO_SOURCE))
################################################################################

define DOWNLOAD
	@echo $(1)
	@echo $(2)
	@echo $(DOWNLOAD_DIR)
	$(Q)test -e $(DOWNLOAD_DIR)/$(2) || \
	for site in $(call qstrip,$(DOWN_DEF_SITE)) $(1); \
	do $(WGET) -P $(DOWNLOAD_DIR) $$site/$(2) && exit; done
endef


